package com.wanxi.reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class GetConstructor {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Class<?> aClass1 = Class.forName("com.wanxi.reflect.Student");
//        Constructor<?> constructor = aClass1.getConstructor();
//        System.out.println(constructor);
//        Constructor<?>[] constructors = aClass1.getConstructors();
//        Constructor<?>[] declaredConstructors = aClass1.getDeclaredConstructors();
//        for (Constructor aa:declaredConstructors
//             ) {
//            System.out.println(aa);
//        }
//        得到类,这里面的参数是可变参数
        Constructor<?> declaredConstructor = aClass1.getDeclaredConstructor(int.class);
//        创建对象 new Student(2);
        declaredConstructor.setAccessible(true);
        Object o = declaredConstructor.newInstance(2);
        Student student= (Student) o;
        System.out.println(student);
    }
}
